﻿using Ducu.GLB.Global;
using Ducu.SRV.ServiceInteface;
using Ducu.GLB.Global.Story;
using Ducu.SRV.ViewModel.Log;
using System;
using System.Web;

namespace Ducu.SRV.UIDevService
{
    public class LogService : ILogService
    {
        public void On(OnModel model, int? days)
        {
            HttpCookie cookie = null;

            if (model.UserName == User.NAME_YEZI)
            {
                cookie = new HttpCookie(CookieName.USER_ID, User.ID_YEZI.ToString());
            }
            if (model.UserName == User.NAME_ABU)
            {
                cookie = new HttpCookie(CookieName.USER_ID, User.ID_ABU.ToString());
            }
            if (model.UserName == HttpContext.Current.Server.HtmlEncode(User.NAME_KESHUICHONG))
            {
                cookie = new HttpCookie(CookieName.USER_ID, User.ID_KESHUICHONG.ToString());
            }

            if (days.HasValue)
            {
                cookie.Expires = DateTime.Now.AddDays(days.Value);
            }

            if (cookie != null)
            {
                HttpContext.Current.Response.Cookies.Add(cookie);
            }

        }


        public void Off()
        {
            if (HttpContext.Current.Request.Cookies[CookieName.USER_ID] != null)
            {
                HttpCookie myCookie = new HttpCookie(CookieName.USER_ID);
                myCookie.Expires = DateTime.Now.AddDays(-1);
                HttpContext.Current.Response.Cookies.Add(myCookie);
            }
        }


        public bool HasPassed(OnModel model)
        {
            return model.Password == "1234";
        }
    }
}
